package org.example.config;

import lombok.Data;
import lombok.Value;
import org.example.common.GlobalConts;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.MailSender;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
public class EmailConfig {
    /**
     * #smtp主机
     * qq邮箱：
     * smtp.qq.com
     * sina邮箱：
     * smtp.sina.cn
     * aliyun邮箱：
     * smtp.aliyun.com
     * 163邮箱：
     * smtp.163.com
     */
    private static String host = "smtp.qq.com";
    /**
     * qq邮箱：
     * 端口号465或587
     * 163邮箱：
     * 端口号465或994
     */
    private static Integer port = 587;
    /**
     * 邮件发送者
     */
    private static String username = GlobalConts.EMAIL_USERNAME;
    /**
     * 配置密码,注意不是真正的密码，而是qq邮箱开通smtp申请的授权码
     */
    static JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
    private static String password = GlobalConts.EMAIL_PASSWORD;

    static {
        javaMailSender.setHost(host);
        javaMailSender.setPort(port);
        javaMailSender.setUsername(username);
        javaMailSender.setPassword(password);
        System.out.println("创建JavaMailSender成功");
    }

    @Bean()
    public JavaMailSender javaMailSender() {
        return javaMailSender;
    }
}